#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单测试知识点描述功能
"""

import requests
import json

# 配置
BASE_URL = "http://localhost:8000"
ADMIN_TOKEN = "admin_secret_token_2024"

def test_simple():
    """简单测试"""
    print("🧪 简单测试知识点描述功能")
    
    # 测试数据
    test_data = {
        "knowledge_point": "Python基础语法测试",
        "count": 2,
        "difficulty": "easy",
        "topic": "编程基础",
        "batch_mode": False
    }
    
    print("📝 发送AI生成请求...")
    print(f"   知识点: {test_data['knowledge_point']}")
    print(f"   难度: {test_data['difficulty']}")
    print(f"   主题: {test_data['topic']}")
    
    try:
        response = requests.post(
            f"{BASE_URL}/admin/ai-generate",
            headers={
                "Authorization": f"Bearer {ADMIN_TOKEN}",
                "Content-Type": "application/json"
            },
            json=test_data,
            timeout=30
        )
        
        print(f"📊 响应状态: {response.status_code}")
        
        if response.status_code == 200:
            result = response.json()
            print("✅ 生成成功!")
            
            if 'generation_info' in result and 'new_bank' in result['generation_info']:
                bank_info = result['generation_info']['new_bank']
                print(f"📁 新题库名称: {bank_info['name']}")
                print(f"📄 题库描述: {bank_info['description']}")
                print(f"✅ 是否激活: {bank_info['is_active']}")
                
                # 检查描述是否包含知识点信息
                if test_data['knowledge_point'] in bank_info['description']:
                    print("🎉 成功! 题库描述包含了输入的知识点信息")
                else:
                    print("⚠️  警告: 题库描述中未找到知识点信息")
            else:
                print("⚠️  警告: 响应中缺少题库信息")
                
        else:
            print(f"❌ 生成失败: {response.status_code}")
            try:
                error_info = response.json()
                print(f"   错误详情: {error_info}")
            except:
                print(f"   错误文本: {response.text}")
                
    except Exception as e:
        print(f"❌ 请求异常: {str(e)}")

if __name__ == "__main__":
    test_simple()
